<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\Province;
use App\Models\City;

class CitySeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // 获取省份
        $beijing = Province::where('code', '110000')->first();
        $tianjin = Province::where('code', '120000')->first();
        $hebei = Province::where('code', '130000')->first();
        $heilongjiang = Province::where('code', '230000')->first();
        $shanghai = Province::where('code', '310000')->first();
        $jiangsu = Province::where('code', '320000')->first();
        $zhejiang = Province::where('code', '330000')->first();
        $guangdong = Province::where('code', '440000')->first();

        $cities = [
            // 北京市
            ['province_id' => $beijing->id, 'name' => '北京市', 'code' => '110100', 'sort_order' => 1],
            
            // 天津市
            ['province_id' => $tianjin->id, 'name' => '天津市', 'code' => '120100', 'sort_order' => 1],
            
            // 河北省
            ['province_id' => $hebei->id, 'name' => '石家庄市', 'code' => '130100', 'sort_order' => 1],
            ['province_id' => $hebei->id, 'name' => '唐山市', 'code' => '130200', 'sort_order' => 2],
            ['province_id' => $hebei->id, 'name' => '秦皇岛市', 'code' => '130300', 'sort_order' => 3],
            ['province_id' => $hebei->id, 'name' => '邯郸市', 'code' => '130400', 'sort_order' => 4],
            ['province_id' => $hebei->id, 'name' => '邢台市', 'code' => '130500', 'sort_order' => 5],
            ['province_id' => $hebei->id, 'name' => '保定市', 'code' => '130600', 'sort_order' => 6],
            ['province_id' => $hebei->id, 'name' => '张家口市', 'code' => '130700', 'sort_order' => 7],
            ['province_id' => $hebei->id, 'name' => '承德市', 'code' => '130800', 'sort_order' => 8],
            ['province_id' => $hebei->id, 'name' => '沧州市', 'code' => '130900', 'sort_order' => 9],
            ['province_id' => $hebei->id, 'name' => '廊坊市', 'code' => '131000', 'sort_order' => 10],
            ['province_id' => $hebei->id, 'name' => '衡水市', 'code' => '131100', 'sort_order' => 11],
            
            // 黑龙江省
            ['province_id' => $heilongjiang->id, 'name' => '哈尔滨市', 'code' => '230100', 'sort_order' => 1],
            ['province_id' => $heilongjiang->id, 'name' => '齐齐哈尔市', 'code' => '230200', 'sort_order' => 2],
            ['province_id' => $heilongjiang->id, 'name' => '鸡西市', 'code' => '230300', 'sort_order' => 3],
            ['province_id' => $heilongjiang->id, 'name' => '鹤岗市', 'code' => '230400', 'sort_order' => 4],
            ['province_id' => $heilongjiang->id, 'name' => '双鸭山市', 'code' => '230500', 'sort_order' => 5],
            ['province_id' => $heilongjiang->id, 'name' => '大庆市', 'code' => '230600', 'sort_order' => 6],
            ['province_id' => $heilongjiang->id, 'name' => '伊春市', 'code' => '230700', 'sort_order' => 7],
            ['province_id' => $heilongjiang->id, 'name' => '佳木斯市', 'code' => '230800', 'sort_order' => 8],
            ['province_id' => $heilongjiang->id, 'name' => '七台河市', 'code' => '230900', 'sort_order' => 9],
            ['province_id' => $heilongjiang->id, 'name' => '牡丹江市', 'code' => '231000', 'sort_order' => 10],
            ['province_id' => $heilongjiang->id, 'name' => '黑河市', 'code' => '231100', 'sort_order' => 11],
            ['province_id' => $heilongjiang->id, 'name' => '绥化市', 'code' => '231200', 'sort_order' => 12],
            ['province_id' => $heilongjiang->id, 'name' => '大兴安岭地区', 'code' => '232700', 'sort_order' => 13],
            
            // 上海市
            ['province_id' => $shanghai->id, 'name' => '上海市', 'code' => '310100', 'sort_order' => 1],
            
            // 江苏省
            ['province_id' => $jiangsu->id, 'name' => '南京市', 'code' => '320100', 'sort_order' => 1],
            ['province_id' => $jiangsu->id, 'name' => '无锡市', 'code' => '320200', 'sort_order' => 2],
            ['province_id' => $jiangsu->id, 'name' => '徐州市', 'code' => '320300', 'sort_order' => 3],
            ['province_id' => $jiangsu->id, 'name' => '常州市', 'code' => '320400', 'sort_order' => 4],
            ['province_id' => $jiangsu->id, 'name' => '苏州市', 'code' => '320500', 'sort_order' => 5],
            ['province_id' => $jiangsu->id, 'name' => '南通市', 'code' => '320600', 'sort_order' => 6],
            ['province_id' => $jiangsu->id, 'name' => '连云港市', 'code' => '320700', 'sort_order' => 7],
            ['province_id' => $jiangsu->id, 'name' => '淮安市', 'code' => '320800', 'sort_order' => 8],
            ['province_id' => $jiangsu->id, 'name' => '盐城市', 'code' => '320900', 'sort_order' => 9],
            ['province_id' => $jiangsu->id, 'name' => '扬州市', 'code' => '321000', 'sort_order' => 10],
            ['province_id' => $jiangsu->id, 'name' => '镇江市', 'code' => '321100', 'sort_order' => 11],
            ['province_id' => $jiangsu->id, 'name' => '泰州市', 'code' => '321200', 'sort_order' => 12],
            ['province_id' => $jiangsu->id, 'name' => '宿迁市', 'code' => '321300', 'sort_order' => 13],
            
            // 浙江省
            ['province_id' => $zhejiang->id, 'name' => '杭州市', 'code' => '330100', 'sort_order' => 1],
            ['province_id' => $zhejiang->id, 'name' => '宁波市', 'code' => '330200', 'sort_order' => 2],
            ['province_id' => $zhejiang->id, 'name' => '温州市', 'code' => '330300', 'sort_order' => 3],
            ['province_id' => $zhejiang->id, 'name' => '嘉兴市', 'code' => '330400', 'sort_order' => 4],
            ['province_id' => $zhejiang->id, 'name' => '湖州市', 'code' => '330500', 'sort_order' => 5],
            ['province_id' => $zhejiang->id, 'name' => '绍兴市', 'code' => '330600', 'sort_order' => 6],
            ['province_id' => $zhejiang->id, 'name' => '金华市', 'code' => '330700', 'sort_order' => 7],
            ['province_id' => $zhejiang->id, 'name' => '衢州市', 'code' => '330800', 'sort_order' => 8],
            ['province_id' => $zhejiang->id, 'name' => '舟山市', 'code' => '330900', 'sort_order' => 9],
            ['province_id' => $zhejiang->id, 'name' => '台州市', 'code' => '331000', 'sort_order' => 10],
            ['province_id' => $zhejiang->id, 'name' => '丽水市', 'code' => '331100', 'sort_order' => 11],
            
            // 广东省
            ['province_id' => $guangdong->id, 'name' => '广州市', 'code' => '440100', 'sort_order' => 1],
            ['province_id' => $guangdong->id, 'name' => '韶关市', 'code' => '440200', 'sort_order' => 2],
            ['province_id' => $guangdong->id, 'name' => '深圳市', 'code' => '440300', 'sort_order' => 3],
            ['province_id' => $guangdong->id, 'name' => '珠海市', 'code' => '440400', 'sort_order' => 4],
            ['province_id' => $guangdong->id, 'name' => '汕头市', 'code' => '440500', 'sort_order' => 5],
            ['province_id' => $guangdong->id, 'name' => '佛山市', 'code' => '440600', 'sort_order' => 6],
            ['province_id' => $guangdong->id, 'name' => '江门市', 'code' => '440700', 'sort_order' => 7],
            ['province_id' => $guangdong->id, 'name' => '湛江市', 'code' => '440800', 'sort_order' => 8],
            ['province_id' => $guangdong->id, 'name' => '茂名市', 'code' => '440900', 'sort_order' => 9],
            ['province_id' => $guangdong->id, 'name' => '肇庆市', 'code' => '441200', 'sort_order' => 10],
            ['province_id' => $guangdong->id, 'name' => '惠州市', 'code' => '441300', 'sort_order' => 11],
            ['province_id' => $guangdong->id, 'name' => '梅州市', 'code' => '441400', 'sort_order' => 12],
            ['province_id' => $guangdong->id, 'name' => '汕尾市', 'code' => '441500', 'sort_order' => 13],
            ['province_id' => $guangdong->id, 'name' => '河源市', 'code' => '441600', 'sort_order' => 14],
            ['province_id' => $guangdong->id, 'name' => '阳江市', 'code' => '441700', 'sort_order' => 15],
            ['province_id' => $guangdong->id, 'name' => '清远市', 'code' => '441800', 'sort_order' => 16],
            ['province_id' => $guangdong->id, 'name' => '东莞市', 'code' => '441900', 'sort_order' => 17],
            ['province_id' => $guangdong->id, 'name' => '中山市', 'code' => '442000', 'sort_order' => 18],
            ['province_id' => $guangdong->id, 'name' => '潮州市', 'code' => '445100', 'sort_order' => 19],
            ['province_id' => $guangdong->id, 'name' => '揭阳市', 'code' => '445200', 'sort_order' => 20],
            ['province_id' => $guangdong->id, 'name' => '云浮市', 'code' => '445300', 'sort_order' => 21],
        ];

        foreach ($cities as $city) {
            City::create($city);
        }
    }
}